home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Art / I / IMAGE 1.45.cpt / Macros / LUT Macros < prev    next >
Encoding:
Text File  |  1992-07-01  |  5.8 KB  |  306 lines  |  [TEXT/MSWD]

  1. macro 'Export LUT [E]';
  2. {
  3. Copies the current look-up table to the Area(Red), Mean(Green) and
  4. Perimeter/Length(blue) columns. Use the Export command to copy
  5. it to a tab-delimeted text file. Max Measurements must be set to
  6. 256 or greater.
  7. }
  8. var
  9.   i:integer;
  10.   v:real;
  11. begin
  12.   SetCounter(256); {SetCounter new in V1.41}
  13.   MeasureArea(true);
  14.   MeasureDensity(true);
  15.   MeasurePerimeter(true);
  16.   for i:=0 to 255 do begin
  17.     rArea[i+1]:=RedLut[i];
  18.     rMean[i+1]:=GreenLut[i];
  19.     rLength[i+1]:=BlueLut[i];
  20.   end;
  21.   ShowResults;
  22.   {Export;}
  23. end;
  24.  
  25.  
  26. macro 'Invert LUT [I]';
  27. var
  28.   i:integer;
  29. begin
  30.   for i:=1 to 254 do begin
  31.     RedLUT[i]:=255-RedLut[i];
  32.     GreenLUT[i]:=255-GreenLut[i];
  33.     BlueLUT[i]:=255-BlueLut[i];
  34.   end;
  35.   UpdateLUT;
  36. end;
  37.  
  38.  
  39. macro 'Random Colors [C]';
  40. var
  41.   i,colors,entries,first,last,r,g,b:integer;
  42. begin
  43.   colors:=25;;
  44.   entries:=256/colors;
  45.   if entries>256 then entries:=256;
  46.   repeat 
  47.     first:=random*255;
  48.     last:=first+entries-1;
  49.     if last>255 then last:=255;
  50.     r:=random*255;
  51.     g:=random*255;
  52.     b:=random*255;
  53.     for i:=first to last do begin
  54.       RedLUT[i]:=r;
  55.       GreenLUT[i]:=g;
  56.       BlueLUT[i]:=b;
  57.     end;
  58.     UpdateLUT;
  59.   until button;
  60. end;
  61.  
  62.  
  63. macro 'Log Tranform';
  64. var
  65.   i,v:integer;
  66.   ln255:real;
  67. BEGIN
  68.   RedLUT[255]:=0;
  69.   GreenLUT[255]:=0;
  70.   BlueLUT[255]:=0;
  71.   ln255:=ln(255);
  72.   for i:=1 to 255 DO begin
  73.     v:=round(ln(i)*255.0/ln255);
  74.     RedLUT[255-i]:=v;
  75.     GreenLUT[255-i]:=v;
  76.     BlueLUT[255-i]:=v;
  77.   end;
  78.   UpdateLUT;
  79. END.
  80.  
  81.  
  82. macro 'Gamma Tranform [G]';
  83. var
  84.   i,v:integer;
  85.   n,mode,min,max:integer
  86.   gamma,mean:real;
  87. begin
  88.   gamma:=GetNumber('Gamma(0.1-3.0):',2);
  89.   measure;
  90.   GetResults(n,mean,mode,min,max);
  91.   ShowMessage('min=',min:1,'\max=',max:1);
  92.   for i:=1 to 254 DO begin
  93.     if (i>min) and (i<max)
  94.       then v:=exp(gamma*ln((i-min)/(max-min)))*255 {x^y=exp(y*ln(x)}
  95.       else begin
  96.         if i<=min then v:=0 else v:=255;
  97.       end;
  98.     RedLUT[i]:=255-v;
  99.     GreenLUT[i]:=255-v;
  100.     BlueLUT[i]:=255-v;
  101.   end;
  102.   UpdateLUT;
  103. end;
  104.  
  105.  
  106. macro 'Square Tranform';
  107. var
  108.   i,v:integer;
  109.   sqr255:real;
  110. BEGIN
  111.   sqr255:=sqr(255.0);
  112.   for i:=1 to 255 DO begin
  113.     v:=round(sqr(i)*255.0/sqr255);
  114.     RedLUT[255-i]:=v;
  115.     GreenLUT[255-i]:=v;
  116.     BlueLUT[255-i]:=v;
  117.   end;
  118.   UpdateLUT;
  119. END.
  120.  
  121.  
  122. macro 'Square Root Tranform';
  123. var
  124.   i,v:integer;
  125.   sqrt255:real;
  126. BEGIN
  127.   sqrt255:=sqrt(255.0);
  128.   for i:=1 to 255 DO begin
  129.     v:=round(sqrt(i)*255.0/sqrt255);
  130.     RedLUT[255-i]:=v;
  131.     GreenLUT[255-i]:=v;
  132.     BlueLUT[255-i]:=v;
  133.   end;
  134.   UpdateLUT;
  135. END;
  136.  
  137.  
  138. macro 'Reset LUT [R]';
  139. begin
  140.   ResetGrayMap;
  141. end;
  142.  
  143.  
  144. macro 'Plot LUT [P]';
  145. var
  146.   i,xscale,yscale:real;
  147.   width,height,margin,pwidth,pheight:integer;
  148.   xbase,ybase:integer;
  149. begin
  150.   SaveState;
  151.   margin:=25;
  152.   pwidth:=400;
  153.   pheight:=125;
  154.   width:=pwidth+2*margin;
  155.   height:=pheight*3+2*margin;
  156.   SetNewSize(width,height);
  157.   SetBackground(0); 
  158.   MakeNewWindow('LUT');
  159.   xscale:=(pwidth-2)/256;
  160.   yscale:=(pheight-1)/256;
  161.   SetForeground(252);
  162.   xbase:=margin; ybase:=margin;
  163.   MoveTo(xbase,ybase);
  164.   for i:=0 to 255 do
  165.     LineTo(xbase+i*xscale,ybase+RedLUT[i]*yscale);
  166.   SetForeground(255);
  167.   MakeRoi(xbase,ybase,pwidth,pheight);
  168.   FlipVertical;
  169.   DrawBoundary;
  170.   SetForeground(253);
  171.   ybase:=ybase+pheight-1;
  172.   MoveTo(xbase,ybase);
  173.   for i:=0 to 255 do
  174.     LineTo(xbase+i*xscale,ybase+GreenLUT[i]*yscale);
  175.   SetForeground(255);
  176.   MakeRoi(xbase,ybase,pwidth,pheight);
  177.   FlipVertical;
  178.   DrawBoundary;
  179.   SetForeground(254);
  180.   ybase:=ybase+pheight-1;
  181.   MoveTo(xbase,ybase);
  182.   for i:=0 to 255 do
  183.     LineTo(xbase+i*xscale,ybase+BlueLUT[i]*yscale);
  184.   SetForeground(255);
  185.   MakeRoi(xbase,ybase,pwidth,pheight);
  186.   FlipVertical;
  187.   DrawBoundary;
  188.   KillRoi;
  189.   RedLUT[252]:=255; GreenLUT[252]:=0;   BlueLUT[252]:=0;
  190.   RedLUT[253]:=0;   GreenLUT[253]:=255; BlueLUT[253]:=0;
  191.   RedLUT[254]:=0;   GreenLUT[254]:=0;   BlueLUT[254]:=255;
  192.   UpdateLUT;
  193.   SetFont('Geneva');
  194.   SetFontSize(9);
  195.   SetText('Centered');
  196.   MoveTo(margin+4,height-margin+8);
  197.   writeln(0:1:2);
  198.   MoveTo(margin+pwidth,height-margin+8);
  199.   writeln(255:1:2);
  200.   RestoreState;
  201. end;
  202.  
  203.  
  204. macro 'Show RGB Values [S]';
  205. var
  206.   x,y,v,savex,savey:integer;
  207. begin
  208.   repeat
  209.     savex:=x; savey:=y;
  210.     GetMouse(x,y);
  211.     if (x<>savex) or (y<>savey) then begin
  212.       v:=GetPixel(x,y);
  213.       ShowMessage('loc=',x:1,', ',y:1,
  214.         '\value=',v:1,
  215.         '\RGB=',RedLUT[v]:1,', ',GreenLUT[v]:1,', ',BlueLUT[v]:1);
  216.       wait(.5);
  217.     end;
  218.   until button;
  219. end;
  220.  
  221.  
  222. macro 'Posterize';
  223. var
  224.   level,i:integer
  225.   delta,steps,StepSize,NextStep:real;
  226. begin
  227.   steps:=GetNumber('Number of Gray Steps(2-256):',8);
  228.   StepSize:=256/steps;
  229.   delta:=256/(steps-1);
  230.   NextStep:=trunc(StepSize);
  231.   level:=255;
  232.   for i:=0 to 255 do begin
  233.     if i>=NextStep then begin
  234.       NextStep:=trunc(NextStep+StepSize);
  235.       level:=level-delta;
  236.       UpdateLUT;
  237.     end;
  238.     if level<0 then level:=0;
  239.     RedLUT[i]:=level;
  240.     GreenLUT[i]:=level;
  241.     BlueLUT[i]:=level;
  242.   end;
  243. end;
  244.  
  245.  
  246. macro 'Make Four Ramp LUT';
  247. var
  248.   i,entry:integer;
  249. BEGIN
  250.   entry:=0;
  251.   for i:=0 to 63 DO begin
  252.     RedLUT[entry]:=255-i*4;
  253.     GreenLUT[entry]:=255-i*4;
  254.     BlueLUT[entry]:=255-i*4;
  255.     entry:=entry+1;
  256.   end;
  257.   for i:=0 to 63 DO begin
  258.     RedLUT[entry]:=255-i*4;
  259.     GreenLUT[entry]:=0;
  260.     BlueLUT[entry]:=0;
  261.     entry:=entry+1;
  262.   end;
  263.    for i:=0 to 63 DO begin
  264.     RedLUT[entry]:=0;
  265.     GreenLUT[entry]:=255-i*4;
  266.     BlueLUT[entry]:=0;
  267.     entry:=entry+1;
  268.   end;
  269.   for i:=0 to 63 DO begin
  270.     RedLUT[entry]:=0;
  271.     GreenLUT[entry]:=0;
  272.     BlueLUT[entry]:=255-i*4;
  273.     entry:=entry+1;
  274.   end;
  275. UpdateLUT;
  276. END.
  277.  
  278. macro 'Make Composite Image'
  279. begin
  280.   SelectSlice(1);
  281.   MultiplyByConstant(0.248);
  282.   AddConstant(64);
  283.   SelectSlice(2);
  284.   MultiplyByConstant(0.248);
  285.   AddConstant(128);
  286.   SelectSlice(3);
  287.   MultiplyByConstant(0.248);
  288.   AddConstant(192);
  289. end;
  290.  
  291. macro 'Set Pixels Red';
  292. var
  293.  v:integer;
  294. begin
  295.     v:=GetNumber('Pixel Value(1-254)',10);
  296.     RedLUT[v]:=255;
  297.     GreenLUT[v]:=0;
  298.     BlueLUT[v]:=0;
  299.   end;
  300.   UpdateLUT;
  301. end;
  302.  
  303.  
  304.  
  305.  
  306.